Master these templates; they’re the backbone of graph algorithms.

  • BFS explores by levels (layer-by-layer) and is the ideal algorithm for finding unweighted shortest paths.
  • DFS explores by depth, going as deep as possible before backtracking. This structure is perfect for cycle detection and topological sorting in DAGs.
  • Both algorithms run in efficient O(V+E) time on adjacency lists and use O(V) extra memory.
  • What's Next? We will build upon these traversal methods to tackle weighted shortest paths with Dijkstra's algorithm and explore more applications like maze solving.
 Understand queue vs. stack rules
 Implement BFS/DFS on adjacency lists
 Reconstruct BFS paths via parent
 Detect cycles via DFS (undirected)
 Use timestamps for advanced tasks